﻿Imports System.Collections.Generic
Imports System.Linq
Imports System.Text
Imports LinqTo2DArray

Class SaleOrders

    'Dim _Samples

    Public Function ToObject(ByRef array As Object(,), ByVal hasHeaders As Boolean) As IEnumerable(of SaleOrder)

        Dim iRowStart = If(hasHeaders, 1, 0)
        Dim iEndRow = If(hasHeaders, array.GetUpperBound(0), array.GetUpperBound(0) + 1)

        Return array.Parse(Of SaleOrder)(Function(o As Object()) New SaleOrder( _
                                             If(IsDate(o(0)), o(0), #1/1/1900#) _
                                             , o(1).ToString _
                                             , o(2).ToString _
                                             , o(3).ToString _
                                             , If(IsNumeric(o(4)), CInt(o(4)), 0) _
                                             , If(IsNumeric(o(5)), o(5), 0) _
                                             ), iRowStart, 0, iEndRow, 6)

    End Function

End Class


Class SaleOrder

    Public Sub New(ByVal date_ As Date, ByVal region_ As String, ByVal rep As String, ByVal item_ As String, ByVal units As Integer _
                   , ByVal cost As Double)

        OrderDate = date_
        Region = region_
        Representative = rep
        Item = item_
        UnitCount = units
        UnitCost = cost

    End Sub

    Public OrderDate As DateTime
    Public Region As String
    Public Representative As String
    Public Item As String
    Public UnitCount As Integer = 5
    Public UnitCost As Double
    Public ReadOnly Property Total() As Double
        Get
            Return UnitCount * UnitCost
        End Get
    End Property

    Public Overrides Function ToString() As String
        Return String.Format("{0} {1} {2} {3} {4} {5} {6}", OrderDate, Region, Representative, Item, UnitCount, UnitCost, Total)
    End Function

End Class
